package com.project.frame.common.utils;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * desc
 *
 * @author cjq
 * @date 2021/11/12
 */
public class ThreadPoolUtil {
    /**
     * 核心池的大小
     */
    private static final int CORE_POOL_SIZE = 32;
    /**
     * 最大线程数
     */
    private static final int MAXIMUM_POOL_SIZE = 64;
    /**
     * 线程没有执行任务时最多保持多久时间会终止，只有当线程池中的线程数大于核心池的大小时才起作用
     */
    private static final Long KEEPALIVE_TIME = 60L;
    /**
     * 阻塞队列（用来存储等待执行的任务）长度
     */
    private static final int BLOCKING_QUEUE_SIZE = 10000;

    public static ExecutorService executorService = new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEPALIVE_TIME, TimeUnit.SECONDS,
            new LinkedBlockingQueue<Runnable>(BLOCKING_QUEUE_SIZE), new ThreadPoolExecutor.CallerRunsPolicy());

}
